#!/usr/bin/python
# coding=utf-8
'''
Created on 2011-10-29

@author: jiangxd
'''
from Tkinter import *
from ttk import *
import os.path
import os
import codecs
from translate.bing import *
import views.transview
import views.dictview
import views.dictationview
import views.aboutview

class Dict2TransApp:
	def __init__(self):
		self.master = Tk()
		self.init_master()
		self.transapp = views.transview.TransView(self.master)
		self.dictapp = views.dictview.DictView(self.master)
		self.dictation_app = views.dictationview.DictationView(self.master)
		self.about_app = views.aboutview.AboutView(self.master)
		self.init_widgets(self.master)
	
	def init_master(self):
		curpath = os.path.realpath(".")
		if os.name == 'nt':
			self.master.iconbitmap('images/bookwin.ico')
		else:
			self.master.iconbitmap(bitmap='@%s/images/book.xbm' % curpath)
			self.master.iconmask(bitmap='@%s/images/book.xbm' % curpath)
		self.master.title("Dict2Trans")
			
	
	def init_dict_frame(self, frame):
		pass		

	def init_widgets(self,master):
#		master.iconbitmap(default='trans.ico')
#		Label(master, text='Translator').pack()

		notebook = Notebook(master)
		notebook.pack()
		
		self.dict_frame = Frame(master,name='dict-frame')
		notebook.add(self.dict_frame,text="Dictionary")
		self.dictapp.init_widgets(self.dict_frame)

		self.trans_frame = Frame(master,name='trans-frame')
		notebook.add(self.trans_frame,text="Translator")
		self.transapp.init_widgets(self.trans_frame)
		
		self.dictation_frame = Frame(master,name="dictation-frame")
		notebook.add(self.dictation_frame,text="Dictation")
		self.dictation_app.init_widgets(self.dictation_frame)
		
		self.about_frame = Frame(master,name="about-frame")
		notebook.add(self.about_frame,text="About")
		self.about_app.init_widgets(self.about_frame)
		
		master.bind_all("<Key>",self.on_press,add=True)
		
#		notebook.bind("<<NotebookTabChanged>>",self.on_tab_changed,add=True)
		self.notebook = notebook
	
	def on_ctrl1(self,event,*args):
		self.notebook.select('.dict-frame')
	
	def on_press(self,event,*args):
		if event.keysym == '1' and self.lastkey != None and (self.lastkey.startswith("Alt") or self.lastkey.startswith("Control")):
			self.notebook.select('.dict-frame')
		if event.keysym == '2' and self.lastkey != None and (self.lastkey.startswith("Alt") or self.lastkey.startswith("Control")):
			self.notebook.select('.trans-frame')
		if event.keysym == '3' and self.lastkey != None and (self.lastkey.startswith("Alt") or self.lastkey.startswith("Control")):
			self.notebook.select('.dictation-frame')
		if event.keysym == '4' and self.lastkey != None and (self.lastkey.startswith("Alt") or self.lastkey.startswith("Control")):
			self.notebook.select('.about-frame')
		self.lastkey = event.keysym

	def mainloop(self):
		self.master.mainloop()

#	def on_tab_changed(self,event,*args):
#		if self.notebook.select() == '.dict-frame':
#			self.dict_frame.focus_force()	
#			self.dict_frame.focus_set()
#		else:
#			self.trans_frame.focus_force()
#			self.trans_frame.focus_set()

Dict2TransApp().mainloop()